import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.{SnappySession, SparkSession}

object SnappySessionHelper {
  var snappySession : SnappySession = _

  def disconnect(): Unit = {
    snappySession.stop()
  }


  def connect(strURL:String): Unit = {
    try {
      val conf: SparkConf = new SparkConf()
        .setAppName("APP")
        .set("spark.ui.port", "8080")
        .set("spark.snappydata.connection", strURL)
        .setMaster("local[*]")
        .set("spark.sql.warehouse.dir", "/tmp/warehouse")
//      snappySession = new SnappySession(new SparkContext(conf))
      /**创建snappydate上下文运行环境，需先创建spark上下文运行环境
       * */
      val snappySession:SnappySession=new SnappySession(new SparkContext(conf))
      val sparkSession: SparkSession = SparkSession.builder().config(conf).getOrCreate()

    } catch {
      case ex: Exception =>
        ex.printStackTrace()
    }
  }

}